package models

func (db *DbWrapper) GetUserBuilding(uid int) *UserBuilding {
	u1 := new(UserBuilding)
	db.DbInstance.Where("uid=?", uid).First(&u1)

	return u1
}

func (db *DbWrapper) GetUserBuildings(uid int) []*UserBuilding {
	var items []*UserBuilding
	db.DbInstance.Where("uid=?", uid).Find(&items)
	return items
}

func (db *DbWrapper) GetUserSpecBuilding(bid int, uid int) *UserBuilding {
	u1 := new(UserBuilding)
	db.DbInstance.Where("buildingid=? and uid=? and step=totalstep", bid, uid).First(&u1)
	return u1
}

func (db *DbWrapper) UserBuildingsIncludeNotFinished(uid int, bid int) *UserBuilding {
	u1 := new(UserBuilding)
	db.DbInstance.Where("uid=? and buildingid=? and step!=totalstep", uid, bid).Find(&u1)
	return u1
}

func (db *DbWrapper) UpdateBuilding(id int, p map[string]interface{}) int64 {
	result := db.DbInstance.Model(&UserBuilding{}).Where("id = ?", id).Updates(p)
	return result.RowsAffected
}
